package com.rybbaby.tss.front.tssMemberFollowUpRecord.service.imp;

import com.google.common.collect.ImmutableMap;
import com.rybbaby.tss.core.web.service.imp.BaseServiceImp;
import com.rybbaby.tss.front.tssMemberFollowUpRecord.dao.ITssMemberFollowUpRecordDao;
import com.rybbaby.tss.front.tssMemberFollowUpRecord.entity.TssMemberFollowUpRecord;
import com.rybbaby.tss.front.tssMemberFollowUpRecord.service.ITssMemberFollowUpRecordService;
import com.rybbaby.tss.front.tssStudent.dao.ITssStudentDao;
import com.rybbaby.tss.front.tssStudent.entity.TssStudent;
import com.rybbaby.tss.front.tssStudent.service.ITssStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * @author 雷春琼
 * @description 缴费表数据库操作服务实现
 * @createDate 2017-08-10 上午12:22:55
 */
@Service
@Transactional
public class TssMemberFollowUpRecordImp extends BaseServiceImp<TssMemberFollowUpRecord> implements ITssMemberFollowUpRecordService {
    @Autowired
    private ITssMemberFollowUpRecordDao dao;
    @Autowired
    private ITssStudentDao tssStudentDao;

    @Override
    public List<Map<String, Object>> getDetailListByMemberId(String memberId, Integer type) {
        return dao.getDetailListByMemberId(memberId, type);
    }

    @Override
    public Boolean saveOrUpdateEntity(TssMemberFollowUpRecord entity) {
        boolean bool = true;
        Integer status = entity.getStatus();
        if(status == null){
            TssStudent student = tssStudentDao.get(TssStudent.class,entity.getMemberId());
            status = student.getStuStatus();
            entity.setStatus(status);
        }
        Serializable newId = this.dao.save(entity);
        Integer updateId = this.tssStudentDao.updateParameterById(ImmutableMap.of(("stuStatus"), status, ("updateTime"), new Timestamp(System.currentTimeMillis())), entity.getMemberId());
        if(newId==null||updateId<=0){
            return !false;
        }
        return bool;
    }

}


